{
 "cells": [
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. _nb_pattern_search:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Pattern Search (Hooke and Jeeves)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "An implementation of well-known Hooke and Jeeves Pattern Search <cite data-cite=\"pattern_search\"></cite> for single-objective optimization which makes use of *exploration* and *pattern* moves in an alternating manner. \n",
    "For now, we like to refer to [Wikipedia](https://en.wikipedia.org/wiki/Pattern_search_(optimization)) for more information such as pseudo code and visualizations in the search space."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "code": "algorithms/usage_pattern_search.py"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Best solution found: \n",
      "X = [ 1.43909365e-08  2.67706048e-08  3.00977832e-08 -1.76057619e-09\n",
      "  8.38491800e-09  2.47422459e-09 -2.69819636e-08 -5.50280628e-09\n",
      " -1.56455253e-09 -1.51364049e-08 -3.08362130e-08  2.90061572e-08\n",
      "  1.80050815e-08  6.14398220e-09  1.24700903e-08 -3.17886614e-08\n",
      " -3.02010606e-08  3.17871699e-08  1.95007644e-08 -1.58903699e-08\n",
      " -1.32530098e-08  2.67728035e-08  2.53807925e-08  1.53025370e-08\n",
      "  1.70378850e-08 -3.18198667e-08 -3.16693433e-08 -2.21468238e-08\n",
      " -2.53791078e-08 -7.53820622e-09]\n",
      "F = [8.65408158e-08]\n"
     ]
    }
   ],
   "source": [
    "from pymoo.algorithms.so_pattern_search import PatternSearch\n",
    "from pymoo.factory import get_problem\n",
    "from pymoo.optimize import minimize\n",
    "\n",
    "problem = get_problem(\"ackley\", n_var=30)\n",
    "\n",
    "algorithm = PatternSearch()\n",
    "\n",
    "res = minimize(problem,\n",
    "               algorithm,\n",
    "               seed=1,\n",
    "               verbose=False)\n",
    "\n",
    "print(\"Best solution found: \\nX = %s\\nF = %s\" % (res.X, res.F))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### API"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. autoclass:: pymoo.algorithms.so_pattern_search.PatternSearch\n",
    "    :noindex:"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Raw Cell Format",
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
